package com.hospital.demo.controller.zhangweibo;


import com.hospital.demo.model.zhangweibo.Finance;
import com.hospital.demo.service.zhangweibo.FinanceService;
import com.hospital.demo.util.ResultUtils;
import com.hospital.demo.util.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "资产分配接口")
@CrossOrigin
@RestController
@RequestMapping("/FinanceController")
public class FinanceController {
    @Autowired
    FinanceService financeService;

    @ApiOperation("查询全部分配情况")
    @GetMapping("/SelectAllFinance")
    public ResultVO SelectAllFinance(Integer page, Integer limit) {

        List<Finance> lists = financeService.SelectAllFinance();

        return ResultUtils.success(lists);
    }

//    @ApiOperation("按ID查找分配情况")
//    @PostMapping("/SelectById")
//    public List<Finance> SelectById(Integer fid) {
//        List<Finance> lists = financeService.SelectById(fid);
//        return lists;
//    }
    @ApiOperation("更改数据")
    @PostMapping("/UpdateFinance")
    public Map<String, Object> UpdateFinance(Integer fnumber,Integer fid) {
        Map<String, Object> map = new HashMap<>();
        Integer Flag = financeService.UpdateFinance(fnumber,fid);
        if (Flag == 1) {
            map.put("msg", "操作成功");
        } else {
            map.put("msg", "操作失败");
        }
        return map;
    }
    @ApiOperation("核对")
    @PostMapping("/SelectFnb")
    public Map<String, Object> SelectFnb() {
        Map<String, Object> map = new HashMap<>();
        List<Integer> number = financeService.SelectFnb();
       Integer a= number.get(1)+number.get(2)+number.get(3);
       Integer b = number.get(0);
        if (a>b) {
            map.put("msg", "超支");
        } else {
            map.put("msg", "合格");
        }
        return map;

    }
}
